//
//  BaseTableView.m
//  TakeYouTourTogether
//
//  Created by king on 15/11/26.
//  Copyright © 2015年 king. All rights reserved.
//

#import "BaseTableView.h"

@implementation BaseTableView

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"test" object:nil];
}

#pragma mark - Method initWithFrame:style:
- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if (self) {
        [self createTableView];
    }
    return self;
}
#pragma mark - Method createTableView
- (void)createTableView {
    self.backgroundColor = [self isDayOrNight];
    self.separatorStyle = UITableViewCellSelectionStyleNone;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backValue:) name:@"test" object:nil];
}
#pragma mark - Method isDayOrNight
- (UIColor *)isDayOrNight {
    return [NightTimeModel shareNightTimeModel].isDayOrNight ? [UIColor whiteColor] :[UIColor blackColor];
}
#pragma mark - Method 通知中心
- (void)backValue:(NSNotification *)notification {
    BOOL b = [notification.userInfo[@"1"] boolValue];
    if (b) {
        NSLog(@"我走了");
        [NightTimeModel shareNightTimeModel].isDayOrNight = NO;
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isDayOrNight"];
        self.backgroundColor = [UIColor blackColor];
    } else {
        [NightTimeModel shareNightTimeModel].isDayOrNight = YES;
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isDayOrNight"];
        self.backgroundColor = [UIColor whiteColor];
    }
}

@end
